route.js 908 B

123456789101112131415161718192021222324252627282930313233343536
  1. import { NextResponse } from "next/server";
  2. import { listMonths } from "@/lib/storage";
  3. /**
  4. * GET /api/branches/[branch]/[year]/months
  5. *
  6. * Returns the list of month folders for a given branch and year.
  7. * Example: /api/branches/NL01/2024/months → { months: ["01", "02", ...] }
  8. */
  9. export async function GET(request, ctx) {
  10. const { branch, year } = await ctx.params;
  11. console.log("[/api/branches/[branch]/[year]/months] params:", {
  12. branch,
  13. year,
  14. });
  15. if (!branch || !year) {
  16. return NextResponse.json(
  17. { error: "branch oder year fehlt" },
  18. { status: 400 }
  19. );
  20. }
  21. try {
  22. const months = await listMonths(branch, year);
  23. return NextResponse.json({ branch, year, months });
  24. } catch (error) {
  25. console.error("[/api/branches/[branch]/[year]/months] Error:", error);
  26. return NextResponse.json(
  27. { error: "Fehler beim Lesen der Monate: " + error.message },
  28. { status: 500 }
  29. );
  30. }
  31. }